package com.siti.kindnessplatform.base.biz;

import com.siti.kindnessplatform.base.mapper.HospitalMapper;
import com.siti.kindnessplatform.base.po.Hospital;
import com.siti.kindnessplatform.config.EasyCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class HospitalBiz {

    @Resource
    private HospitalMapper hospitalMapper;

    @Resource
    private EasyCache easyCache;

    public static final String HOSPITALLIST = "hospitallist";

    public static final String RK001 = "rk001";

    private static final Logger logger = LoggerFactory.getLogger("HospitalBiz");


    public List<Hospital> selectHospital(String content, Integer hour, Integer orgType) {
        List<Hospital> hospitals = null;
        if (content == null && hour == null) {
        	try {
        		hospitals = (List<Hospital>) easyCache
        				.putAndGetSupplier("hospitallistType"+orgType,
                                RK001, () -> {
        							List<Hospital> list = hospitalMapper.selectHospital(content, hour, orgType);
                                    return list;
        						});
            } catch (Exception e) {
                logger.error("查询所有医院错误{}",e.getMessage());
                return null;
            }
        } else {
            hospitals = hospitalMapper.selectHospital(content, hour, orgType);
        }
        return hospitals;
    }

    public List<String> findTopCity(Integer top,Integer orgType) {
        return hospitalMapper.findTopCity(top,orgType);
    }

    public List<String> findTopProvince(Integer top,Integer orgType) {
        return hospitalMapper.findTopProvince(top,orgType);
    }

    public List<String> findTopSupplies(Integer top,Integer orgType) {
        return hospitalMapper.findTopSupplies(top,orgType);
    }

}
